from pages.BasePage import Basepage
from selenium.webdriver.common.by import By


class LoginPage(Basepage):
    __default_account = 'admin'
    __default_password = '123456'
    __default_authCode = '8888'
    __loc_account = (By.XPATH, '//*[contains(@placeholder, "用户名")]')
    __loc_password = (By.XPATH, '//*[contains(@placeholder, "密码")]')
    __loc_authCode = (By.XPATH, '//*[contains(@placeholder, "验证码")]')
    __loc_loginButton = (By.CSS_SELECTOR, 'button')

    def __init__(self, browser):
        super().__init__(browser)

    def __input_account(self, account):
        self.find_ele(self.__loc_account).send_keys(account)

    def __input_password(self, password):
        self.find_ele(self.__loc_password).send_keys(password)

    def __input_authcode(self, authCode):
        self.find_ele(self.__loc_authCode).send_keys(authCode)

    def __click_loginButton(self):
        self.find_ele(self.__loc_loginButton).click()

    def login(self, account=__default_account, password=__default_password, authCode=__default_authCode):
        self.__input_account(account)
        self.__input_password(password)
        self.__input_authcode(authCode)
        self.__click_loginButton()
